<?php
namespace wlcat\http\view;
use wlcat\src\Register;

class View
{
    protected $variables = array();
    protected $_controller;
    protected $_action;
    protected $smarty;

    function __construct($controller, $action)
    {
        $this->_controller = $controller;
        $this->_action = $action;
        $this->smarty  = Register::get(Register::SMARTY_CLASS);
        $this->smarty->setTemplateDir(C('smarty.templateDir'));
        $this->smarty->setCompileDir(C('smarty.compileDir'));
        $this->smarty->setCacheDir(C('smarty.cacheDir'));
        $this->smarty->setCache(C('smarty.cache'));
        $this->smarty->setCacheTime(C('smarty.cache_lifetime'));
        $this->smarty->setDebug(C('debugging'));
    }
    /** 分配变量 **/
    function assign($name, $value)
    {
        $this->smarty->assign($name, $value);
    }
    /** 渲染显示 **/
    function display($file = '')
    {
        $path       = empty($file)
                        ?  $this->_controller . '/' . $this->_action . '.php'
                        :  $file;
        $this->smarty->display($path);
    }

}